import java.util.HashMap;
import java.util.Map;

/**
 * @Author ZhangCuirong
 * @Date 2025/8/13 11:18
 * @description:
 */
public class Solution454 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> sumMap = new HashMap<>();
        int res = 0;
        for (int i : nums1) {
            for (int j : nums2) {
                int sum = i + j;
                sumMap.put(sum, sumMap.getOrDefault(sum, 0) + 1);
            }
        }

        for (int i : nums3) {
            for (int j : nums4) {
                int sum = -i - j;
                res += sumMap.getOrDefault(sum, 0);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums1 = {1, 2};
        int[] nums2 = {-2, -1};
        int[] nums3 = {-1, 2};
        int[] nums4 = {0, 2};
        Solution454 solution = new Solution454();
        System.out.println(solution.fourSumCount(nums1, nums2, nums3, nums4));
    }
}
